//
//  SKUDetailTakeinTbCell.m
//  ZITHER
//
//  Created by weixin on 2018/8/17.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "SKUDetailTakeinTbCell.h"

@implementation SKUDetailTakeinTbCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.backgroundColor = [UIColor randomColor];
    [self.imageUser setCornerRadiusWithRadius:30 isMasks:YES];
    self.imageUser.clipsToBounds = YES;
    
    [self.btnMapIcon setCornerRadiusWithRadius:17.5 isMasks:YES];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
    
    [[tap rac_gestureSignal] subscribeNext:^(id x) {
        
        self.scrPic.backgroundColor = [UIColor randomColor];
        
        NSMutableString *str=[[NSMutableString alloc]initWithFormat:@"电话号码:%@",self.bizPhone.text];
        
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:str preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        }];
        UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"呼叫" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",self.bizPhone.text]];
            [[UIApplication sharedApplication] openURL:url];
        }];
        // Add the actions.
        
        [alertController addAction:cancelAction];
        
        [alertController addAction:otherAction];
        
        [self.getNav presentViewController:alertController animated:YES completion:nil];
    }];
    self.bizPhone.userInteractionEnabled = YES;
    [self.bizPhone addGestureRecognizer:tap];
    
    
    

                          
                          
    
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] init];
    
    [[tap1 rac_gestureSignal] subscribeNext:^(id x) {
        UIPasteboard *pab = [UIPasteboard generalPasteboard];
        NSString *string = self.bizWechat.text;
        [pab setString:string];
        if (pab == nil) {
            [Tools showTips:@"复制失败"];
            
        }else{
            [Tools showTips:@"已复制"];
        }
        
        
        NSURL *url = [NSURL URLWithString:@"weixin://"];
        
        [[UIApplication sharedApplication] openURL:url];
        
        
        
        
       
    }];
    self.bizWechat.userInteractionEnabled = YES;
    [self.bizWechat addGestureRecognizer:tap1];

}


-(void)setModel:(AcceptPriceListModel *)model{
    
    _model = model;
    
    [self.scrPic addScrImage:model.fileList imageHeight:80];

    NSString *str = [NSString stringWithFormat:@"%@%@",RootUrlImage,model.bizPortrait];

    [self.imageUser sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"watchSmale"]];
    
    
    
    [self.imgeMap sd_setImageWithURL:[NSURL URLWithString:[NSString getMapImageView:model.latitude markers:model.longitude]] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
//        NSLog(@"map ==== %@ %@ ")
        self.imgeMap.image = image.grayImage;//图片变灰

    }];
    
    
    
    
    self.labUserName.text = model.bizNickName;
    self.labUserProvince.text = [NSString stringWithFormat:@"%@%@%@%@",model.province,model.city,model.area,model.bizAddr];
//    self.bizAddr.text = model.bizAddr;
    self.bizPhone.text = model.bizPhone;
    self.bizWechat.text = model.bizWechat;
    
    
    NSString *strNUM =@"";
    if (model.goodsSourcePrice.length>0) {
        strNUM = model.goodsSourcePrice;
    }else{
        strNUM = model.goodSourcePrice;
    }
    
//    NSString *strNUM = model.goodsSourcePrice;

//    if (self.type) {
//        strNUM = model.goodSourcePrice;
//    }
    int priceInt = [strNUM intValue];

//    int priceInt = [model.goodsSourcePrice intValue];
    
    
    
    
    if (self.type) {
        NSNumberFormatter *moneyFormatter = [[NSNumberFormatter alloc] init];
        moneyFormatter.positiveFormat = @"###,##0";
        NSString *formatString = [moneyFormatter stringFromNumber:@(priceInt)];
        //    self.goodSourcePrice.text =[NSString stringWithFormat:@"¥ %@",formatString];
        self.goodSourcePrice.text =[NSString stringWithFormat:@"¥ %@",formatString];
    }else{
        NSNumberFormatter *moneyFormatter = [[NSNumberFormatter alloc] init];
        moneyFormatter.positiveFormat = @"###,##0";
        NSString *formatString = [moneyFormatter stringFromNumber:@(priceInt)];
        //    self.goodSourcePrice.text =[NSString stringWithFormat:@"¥ %@",formatString];
        self.goodSourcePrice.text =[NSString stringWithFormat:@"¥ %@",formatString];
    }
    


//    if (model.goodSourcePrice.length != 0) {
//
//    }else{
//        NSNumberFormatter *moneyFormatter = [[NSNumberFormatter alloc] init];
//        moneyFormatter.positiveFormat = @"###,##0";
//        NSString *formatString = [moneyFormatter stringFromNumber:@(priceInt)];
//        self.goodSourcePrice.text =[NSString stringWithFormat:@"¥ %@",formatString];
//    }
    self.textView.text = model.sourceDesc;
    
    CGRect frame = self.textView.frame;
    frame.size.height = [NSString textHeight:self.model.sourceDesc font:15 width:kScreenW-36];
    self.textView.frame = frame;
    
    if (self.model.fileList.count>0) {

        self.scrollview.frame = CGRectMake(0,CGRectGetMaxY(self.textView.frame)+15 , kScreenW-30,60);
        self.scrollview.hidden = NO;
        [self.scrollview.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        self.scrollview.contentSize = CGSizeMake(self.model.fileList.count*68+15,0);
        
        for (int j = 0; j<self.model.fileList.count; j++) {
            UIImageView * imageV = [[UIImageView alloc]initWithFrame:CGRectMake(j*68+15,0, 60,60)];
            [imageV setCornerRadiusWithRadius:5 isMasks:YES];
            imageV.backgroundColor = [UIColor whiteColor];
            imageV.contentMode = UIViewContentModeScaleAspectFill;
            
            NSString *str = [NSString stringWithFormat:@"%@%@",RootUrlImage,self.model.fileList[j]];
            
            [imageV sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"watchSmale"]];
            
            [self.scrollview addSubview:imageV];
        }
        
    }else{
        self.scrollview.hidden = YES;
    }
}

-(UIScrollView *)scrollview{
    if (!_scrollview) {
        _scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(self.textView.frame)+35 , kScreenW,60)];
        _scrollview.bounces = NO;
        _scrollview.showsHorizontalScrollIndicator = NO;
        _scrollview.contentSize = CGSizeMake(kScreenW*3,0);
        _scrollview.bounces = NO; // 默认为YES 取消设置NO
        // 当bounces属性为NO时，以下两个属性设置无效
        _scrollview.alwaysBounceHorizontal = YES; // 水平方向弹簧效果
        _scrollview.alwaysBounceVertical = YES; // 垂直方向弹簧效果
        _scrollview.decelerationRate = 0.1; // 值域 0~1 值越小减速停止的时间越短
        _scrollview.backgroundColor = [UIColor whiteColor];
        [self.viewBackBottom addSubview:_scrollview];
    }
    return _scrollview;
}


@end
